<script setup lang="ts">
import { ref, watch } from "vue";
import { useRoute } from "vue-router";

import Dashboard from "./components/Dashboard.vue";
import Intelligence from "./components/Intelligence.vue";
import Workflow from "./components/Workflow.vue";
import Assets from "./components/Assets.vue";
import Verification from "./components/Verification/index.vue";
import SchedulerConfig from "./components/SchedulerConfig.vue";
import VulnerabilityManage from "./components/VulnerabilityManage/index.vue";

const route = useRoute();
const activeTab = ref("0");

// 获取URL参数中的task
const taskParam = ref((route.query.task as string) || "");

// 监听URL参数中的tab，用于从详情页返回时激活对应的tab
watch(
  () => route.query.tab,
  (newTab) => {
    if (newTab && typeof newTab === "string") {
      activeTab.value = newTab;
    }
  },
  { immediate: true }
);
</script>

<template>
  <div>
    <el-tabs type="border-card" v-model="activeTab">
      <el-tab-pane label="情报仪表板" value="0">
        <div
          v-if="taskParam"
          style="display: flex; justify-content: space-between"
        >
          <div class="task-name">任务名称：{{ taskParam }}</div>
        </div>
        <!-- 情报仪表板 -->
        <Dashboard :task="taskParam" />
      </el-tab-pane>
      <el-tab-pane label="情报管理" value="1">
        <div
          v-if="taskParam"
          style="display: flex; justify-content: space-between"
        >
          <div class="task-name">任务名称：{{ taskParam }}</div>
        </div>
        <!-- 情报管理 -->
        <Intelligence :task="taskParam" />
      </el-tab-pane>
      <el-tab-pane label="工作流管理" value="2">
        <div
          v-if="taskParam"
          style="display: flex; justify-content: space-between"
        >
          <div class="task-name">任务名称：{{ taskParam }}</div>
        </div>
        <!-- 工作流管理 -->
        <Workflow :task="taskParam" />
      </el-tab-pane>
      <el-tab-pane label="验证复核" value="3">
        <div
          v-if="taskParam"
          style="display: flex; justify-content: space-between"
        >
          <div class="task-name">任务名称：{{ taskParam }}</div>
        </div>
        <!-- 验证复核 -->
        <Verification :task="taskParam" />
      </el-tab-pane>

      <el-tab-pane label="资产关联" value="4">
        <div
          v-if="taskParam"
          style="display: flex; justify-content: space-between"
        >
          <div class="task-name">任务名称：{{ taskParam }}</div>
        </div>
        <!-- 资产关联 -->
        <Assets :task="taskParam" />
      </el-tab-pane>
      <el-tab-pane label="任务调度器" value="5">
        <SchedulerConfig :task="taskParam" />
      </el-tab-pane>
      <el-tab-pane label="漏洞管理" value="6">
        <VulnerabilityManage :task="taskParam" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<style lang="scss" scoped>
.search-form-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.el-btn-zese {
  background: #722ed1;
  color: white;
  border-color: #722ed1;
}

.el-btn-zese.is-disabled,
.el-btn-zese.is-disabled:focus,
.el-btn-zese.is-disabled:hover {
  background: #722ed1;
  color: white;
  border-color: #722ed1;
}
.task-name {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
  border: 1px solid #e0e0e0;
  padding: 10px;
  border-radius: 5px;
}
</style>
